package com.lxl.priv.bak;

import cn.hutool.core.util.StrUtil;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author xiulong.liu
 * @Date 2024/8月/23/星期五 14:37
 * @Desc
 */
public class CsvDemo {
    public static void main(String[] args) throws Exception{
        CSVPrinter csvPrinter = new CSVPrinter(new BufferedWriter(new FileWriter("/home/xiaoliu/a.csv")),
                CSVFormat.DEFAULT);
        List<String[]> data = new ArrayList<>();
        data. add(new String[]{ "A", "B", "C" });
        data. add(new String[]{ "1", "2", "3" });
        data. add(new String[]{ "A1", "B2", "C3" });
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 3; i++) {
            sb.append(i).append(",");
        }
        sb.setLength(sb.length() - 1);


        //csvPrinter.printRecord(sb.toString());
        csvPrinter.printRecord(StrUtil.trimToEmpty("1"));
        csvPrinter.printRecord(StrUtil.trimToEmpty("2"));
        csvPrinter.printRecords("3");
        csvPrinter.printRecords(data);
        csvPrinter.flush();
    }
}
